
var deleteID = '';
var vm = new Vue({
    el:"#nameCardList",
    data:{
        nameCardList:'',
    },
    // 方法存放区
    methods: {

        //获取名片列表
        getAllNameCardListInfo() {
            axios({
                method: 'POST',
                url: 'http://localhost:8099/personalNameCard/getNameCardList',
            }).then(function (result) {
                vm.nameCardList = result.data;

                // console.log(vm.userId)
            }).catch(function (reason) {
                console.log(reason);
            })
        },


        //添加名片
        addNameCard() {
            axios({
                method: 'POST',
                url: 'http://localhost:8099/personalNameCard/NameCardYZ',
            }).then(function (result) {
                if(result.data){
                    alert("该分类已有你的名片")
                }else {

                    axios({
                        method: 'POST',
                        url: 'http://localhost:8099/personalNameCard/addNameCard',
                    }).then(function (result) {
                        if(result.data){
                            alert("添加成功");
                            getAllNameCardListInfo();
                        }else {
                            alert("添加失败")
                        }
                    }).catch(function (reason) {
                        console.log(reason);
                    })


                }

            }).catch(function (reason) {
                console.log(reason);
            })


        },
        //跳转移动页面
        goRemove(namecardlistId){
            location.href="nameCardRemove.html?id="+namecardlistId
        },

        //跳转修改页面
        updateNameCard(namecardlistId) {
            axios({
                method: 'POST',
                url: 'http://localhost:8099/personalNameCard/getNameCardList'
            }).then(function (result) {
                location.href="nameCardUpdate.html?id="+namecardlistId
                // console.log(vm.nameCardList)
            }).catch(function (reason) {
                console.log(reason);
            })
        },

        // 删除
        deleteNameCard(namecardlistId) {
            deleteID = namecardlistId;
            $(".tip").fadeIn(200);
        },

        // 删除确认
        delectCheck() {
            console.log(deleteID)
            axios.post('http://localhost:8099/personalNameCard/delete/' +deleteID)
                .then(function (response) {
                    // alert(response.data)
                    vm.getAllNameCardListInfo();
                })
                .catch(function (error) {
                    alert(response.data)
                });
        },

    },

    //页面加载完自动执行
    mounted(){
        this.getAllNameCardListInfo();
    }

})